﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Cronus.ViewModel.Data;

namespace Cronus.ViewModel
{
    /// <summary>
    /// Provides a summary of time worked on a specific task.
    /// </summary>
    public class TaskSummary : SummaryBase
    {
        //*** Constants ***//
        //*** Static ***//
        //*** Member Variables ***//
        private DataModel _DataModel;
        private string _TaskName;

        public string Name
        {
            get
            {
                if (String.IsNullOrEmpty(_TaskName))
                    return "Total";
                return _TaskName;
            }
        }

        //*** Properties ***//
        //*** Constructors ***//
        /// <summary>
        /// Default constructor.  Returns summary of all tasks, not a specific task.
        /// </summary>
        public TaskSummary(DataModel aDataModel) : this(aDataModel, null)
        {
        }

        /// <summary>
        /// Constructor that takes the task name to return a summary of.
        /// </summary>
        /// <param name="strTaskName">Name of the task to provide a summary of.</param>
        public TaskSummary(DataModel aDataModel, Task task)
        {
            _DataModel = aDataModel;
            _TaskName = (null != task) ? task.TaskName : String.Empty;
        }

        //*** Abstract Methods ***//
        //*** Methods ***//
        /// <summary>
        /// Query for the total amount of time associated with this task in the given time span.
        /// </summary>
        /// <param name="aStartDate">Start of the time period to query on.</param>
        /// <param name="anEndDate">End of the time period to query on.</param>
        /// <returns>Total number of hours in the time span.</returns>
        protected override double QueryForHoursInRange(DateTime aStartDate, DateTime anEndDate)
        {
            QueryTaskInformation aTaskQuery = new QueryTaskInformation(_DataModel);
            TimeSpan allTaskHours = new TimeSpan(0);

            // Query the tasks table to get how many hours are in the given date/time range.
            allTaskHours = aTaskQuery.GetTaskHoursInDateRange(_TaskName, aStartDate, anEndDate);
            return allTaskHours.TotalHours;
        }
    }
}
